Skip to content

ci: publish to PyPI with Trusted Publishing from master - #249

Merged
mogita merged 6 commits into
masterfrom
ci/pypi-trusted-publishing
Nov 17, 2026
Merged

mogita merged 6 commits into
masterfrom
ci/pypi-trusted-publishing

Conversation

@mogita

@mogita mogita commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Submit a pull request

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

The release job uploads to PyPI with the long-lived PYPI_TOKEN secret, which may have been exposed in the GitHub Actions secret incident. This switches the upload to PyPI Trusted Publishing: the publish job exchanges its OIDC token for a short-lived PyPI token, so the repo no longer needs a PyPI secret.

  • The release runs on push to master instead of on the closed release PR. A check job releases while PyPI lacks the sdist or the wheel of __version__ from stream_chat/__pkg__.py, which is the case right after a release PR is squash-merged. Any other push to master skips the release. Once the version is tagged, the tagged commit is rebuilt, so a rerun or a later push finishes a failed upload with the same code. Release runs are serialized, so overlapping pushes cannot build the same version twice.
  • build runs checkout, the changelog script and setup.py with contents: read and uploads dist/.
  • release creates the tag and GitHub release on the released commit with contents: write, before the upload, and keeps them on a rerun.
  • publish is the only job with id-token: write. It downloads dist/ and runs pypa/gh-action-pypi-publish v1.14.3, both pinned to a commit, in the pypi environment. That environment allows master only, and the PyPI trusted publisher for stream-chat requires it, so a branch with an edited release.yml cannot publish.

How to verify: the merge of this PR runs check with release=false (4.34.1 is on PyPI) and skips the rest. The next release PR merge publishes to PyPI without PYPI_TOKEN, and its publish step logs a successful token exchange. After that, the PYPI_TOKEN secret and its PyPI token are removed.


Note

Medium Risk
It is the sole release path to PyPI and GitHub; new version detection and job gating could skip or delay a release if misconfigured, but runtime app code is unchanged.

Overview
Replaces the release-on-merged-release-* PR flow with a push to master pipeline that only ships when stream_chat/__pkg__.py’s __version__ is missing sdist or wheel on PyPI.

The workflow is split into check → build → release → publish, with per-job permissions, a release concurrency group, and artifact handoff instead of building and uploading in one job. Version/ref come from the package file (and an existing tag when re-running), not the PR branch name.

PyPI upload drops PYPI_TOKEN / twine in favor of Trusted Publishing (pypi environment, OIDC in publish only). GitHub releases are created before upload, with skipIfReleaseExists and skip-existing on publish for safe reruns.

Reviewed by Cursor Bugbot for commit 1b13dff. Bugbot is set up for automated code reviews on this repo. Configure here.

The release job exchanges its OIDC token for a short-lived PyPI token instead of uploading with the long-lived PYPI_TOKEN secret.
Comment thread .github/workflows/release.yml Resolved
Comment thread .github/workflows/release.yml Resolved
Building runs in its own job, so only the publish job can mint a PyPI token. Releasing on push to master lets the pypi environment allow master only, which a branch run cannot reach.
@mogita mogita changed the title ci: publish to PyPI with Trusted Publishing ci: publish to PyPI with Trusted Publishing from master Nov 17, 2026

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread .github/workflows/release.yml Resolved
A release whose GitHub release step failed can then be finished by rerunning the workflow, instead of failing on the duplicate upload until the tag is created by hand.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread .github/workflows/release.yml Resolved
The tag marks the version as released, so a later push to master skips it instead of rebuilding different code under the same version. A failed upload is finished by rerunning the publish job, which reuses the built files.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread .github/workflows/release.yml Resolved
Checking PyPI instead of the tag lets a full rerun or a later push finish a release whose upload failed. Once the version is tagged, the tagged commit is rebuilt and the existing GitHub release is kept, so the uploaded files always match the tag.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b5e9354. Configure here.

Comment thread .github/workflows/release.yml Resolved
Comment thread .github/workflows/release.yml Resolved
A release counts as done only when PyPI has the sdist and the wheel, so a partial upload is finished by the next run. Serializing the runs keeps overlapping pushes from building the same version from different commits.
@mogita
mogita merged commit e85e7db into master Nov 17, 2026
15 of 16 checks passed
@mogita
mogita deleted the ci/pypi-trusted-publishing branch November 17, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant